package com.hzp.micromall.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzp.micromall.admin.dao.UmsResourceCategoryDao;
import com.hzp.micromall.admin.entity.UmsResourceCategory;
import com.hzp.micromall.admin.service.UmsResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author houzipeng
 * @Date 2022/2/26 0:26
 * @Version 1.0
 * 后台资源分类管理Service实现类
 */
@Service
public class UmsResourceCategoryServiceImpl implements UmsResourceCategoryService {
    @Autowired
    private UmsResourceCategoryDao resourceCategoryDao;

    @Override
    public List<UmsResourceCategory> listAll() {
        LambdaQueryWrapper<UmsResourceCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(UmsResourceCategory::getSort);
        return resourceCategoryDao.selectList(wrapper);
    }

    @Override
    public int create(UmsResourceCategory umsResourceCategory) {
        umsResourceCategory.setCreateTime(new Date());
        return resourceCategoryDao.insert(umsResourceCategory);
    }

    @Override
    public int update(Long id, UmsResourceCategory umsResourceCategory) {
        umsResourceCategory.setId(id);
        return resourceCategoryDao.updateById(umsResourceCategory);
    }

    @Override
    public int delete(Long id) {
        return resourceCategoryDao.deleteById(id);
    }
}